<extend name="Public/layout"/>

<block name="body">
    <div class="row">
        <div class="form-horizontal">
            <div class="col-xs-12">
                <div class="nav-tabs-custom flat">
                    <div class="tab-content no-padding">
                        <div class='tab-pane active' id="tab{$key}">
                            <div class="box-body" style="max-width:900px;">





                                <div class="form-group">
                                    <label class="col-sm-2 control-label" data-name="{$field['name']}">活动名称</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control" name="act_id"
                                               value="{$activity['activity_title']}" readonly="readonly">
                                    </div>
                                </div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">卖家ID</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="shopId"
                                                   value="">
                                        </div>

                                    </div>


                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">卖家昵称:</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="seller_nickname"
                                                   value="">
                                        </div>
                                    </div>


                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">店铺名称:</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="seller_title"
                                            >
                                        </div>
                                    </div>


                                  <!--  <div class="form-group">
                                        <label class="col-sm-2 control-label">店铺类型:</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="type"
                                                   value="" readonly="readonly">
                                        </div>
                                    </div>-->





                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">店铺链接:</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="url"
                                                   value="">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">QQ:</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="qq"
                                                   value="">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">微信号:</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="weixin_name"
                                                   value="">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">运营:</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="operation"
                                                   value="">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">手机号码:</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="mobile"
                                                   value="">
                                        </div>
                                    </div>







                                    <div style="text-align: center;" class="form-group">
                                        <div class="col-sm-10">
                                            <button onclick="goodsSubmit()" style="color: #0a8ddf;width: 200px"
                                                    type="submit">提交
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script>
            $(function () {
                $('.form-control.date.datepicker').change(function () {
                    $(this).prev().val($(this).val());
                });

                $('.datepicker').each(function () {
                    var $this = $(this);
                    var dateType = $(this).attr('data-type');
                    var handle = "datepicker";
                    var format = "yyyy-mm-dd";
                    var options = {
                        language: 'zh-CN',
                        autoclose: true,
                        templates: {
                            leftArrow: '<i class="fa fa-caret-square-o-left"></i>',
                            rightArrow: '<i class="fa fa-long-arrow-right"></i>'
                        },
                    }
                    switch (dateType) {
                        case 'timestamp':
                        case 'datetime':
                            format = "yyyy-mm-dd hh:ii";
                            handle = 'datetimepicker';
                            break;
                        case 'date':
                            format = "yyyy-mm-dd";
                            handle = 'datepicker';
                            break;
                    }
                    options.format = format;
                    var fieldName = $this.attr('data-name');
                    $this[handle](options)
                            .on('changeDate,change', function (e) {
                                var value = $(e.currentTarget).val();
                                $('input[name=' + fieldName + ']').val(value);
                            });
                });
            });



            function goodsSubmit() {
                //
                var taobao_act_id = "{$activity['taobao_act_id']}";
                var shopId = $('input[name="shopId"]').val();
                var seller_nickname = $('input[name="seller_nickname"]').val();
                var seller_title = $('input[name="seller_title"]').val();
                var url = $('input[name="url"]').val();
                var qq = $('input[name="qq"]').val();
                var weixin_name = $('input[name="weixin_name"]').val();
                var operation = $('input[name="operation"]').val();
                var mobile = $('input[name="mobile"]').val();

                $.ajax({
                    url: '{:U("activity/addSeller")}',
                    type: 'post',
                    data: {
                        taobao_act_id: taobao_act_id,
                        shopId: shopId,
                        seller_nickname: seller_nickname,
                        seller_title: seller_title,
                        url: url,
                        qq: qq,
                        weixin_name: weixin_name,
                        operation: operation,
                        mobile: mobile
                    },
                    dataType: 'json',
                    success: function (result) {
                        console.log('****');
                        console.log(result);

                        alert(result.msg);

//                    $treeTable.addChilds($treeTable.build(result.data));


                    }
                });
            }

            function uploadFile() {
                var formData = new FormData($('#uploadForm')[0]);
                $.ajax({
                    type: 'post',
                    dataType: "json",
                    url: "http://zs.jiuyuanmall.cn/api/Upload", //上传文件的请求路径必须是绝对路劲
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                    data: formData,
                    cache: false,
                    processData: false,
                    contentType: false
                }).success(function (data) {
                    alert(data);
                }).error(function () {
                    alert("上传失败");
                });
            }

            function doUpload() {

                let data = new FormData();
                data.append('kcs_uploader_file', $('#file')[0].files[0]);
                let xhr = new XMLHttpRequest();
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        console.log(xhr.responseText);
                        console.log('####');

                        var data = JSON.parse(xhr.responseText).data;
                        var ecode = JSON.parse(xhr.responseText).error_code;

                        console.log(data)
                        if (ecode == 0) {
                            document.getElementById('filename1').value = data.avatar_url;
                            console.log('####');
                            console.log(data.avatar_url)
                        }
                    }
                };
                xhr.open('POST', ( "http://" + location.hostname ) + '/api/Upload');
                xhr.send(data)
            }

            function doUpload2() {

                let data = new FormData();
                data.append('kcs_uploader_file', $('#file2')[0].files[0]);
                let xhr = new XMLHttpRequest();
                xhr.onreadystatechange = function () {
                    if (xhr.readyState == 4 && xhr.status == 200) {
                        console.log(xhr.responseText);
                        console.log('####');

                        var data = JSON.parse(xhr.responseText).data;
                        var ecode = JSON.parse(xhr.responseText).error_code;

                        console.log(data)
                        if (ecode == 0) {
                            document.getElementById('jieshuquan_img').value = data.avatar_url;
                            console.log('####');
                            console.log(data.avatar_url)
                        }
                    }
                };
                xhr.open('POST', ( "http://" + location.hostname ) + '/api/Upload');
                xhr.send(data)
            }


            function sss() {
                var form = new FormData();
                form.file = file;    //file是从文件输入框的change事件中获取到的文件内容
                var uploadUrl = '/upload/images/';    //上传的路径
                try {
                    var xhr;
                    if (window.XMLHttpRequest) {
                        xhr = new XMLHttpRequest();
                    } else if (window.ActiveXObject) {
                        xhr = new ActiveXObject("Microsoft.XMLHttpRequest");
                    } else {
                        console.warn('浏览器版本太低', err);
                        return;
                    }

                    xhr.onreadystatechange = function () {
                        if (xhr.readyState === 4) {
                            const result = JSON.parse(xhr.responseText);
                            if (xhr.status === 200) {
                                // 上传成功
                                console.log(result);
                            } else {
                                // 上传失败
                            }
                        }
                    };

                    xhr.withCredentials = false;
                    xhr.open("POST", uploadUrl, true);
                    xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
                    xhr.setRequestHeader("Content-Type", "multipart/form-data");
                    xhr.send(formData);
                } catch (err) {
                    console.warn('错误：', err);
                }
            }

            /*function doUpload() {
             var formData = new FormData;
             formData.append('file', $('#file')[0].files[0]);
             console.log(8888888);
             console.log($('#file')[0].files[0]);
             $.ajax({
             // url: 'http://zs.sun.com/api/Upload' ,
             url: '{:U("activity/upload")}' ,
             /!*headers : {
             'Content-Type' : "multipart/form-data"
             },*!/
             type: 'POST',
             data:formData,
             // async: false,
             // cache: false,
             processData: false,
             contentType: false,
             success: function (returndata) {
             console.log(returndata);
             },
             error: function (returndata) {
             console.log(returndata);
             }
             });
             }*/
        </script>
</block>